package templates

var ServiceTpl = `package service

import (
	et "{{StructAppPath}}/entities"
	"{{StructAppPath}}/model"
)

type {{StructName}}Service struct {
}
/**
 * 根据多条件查询数据
 */
func (c *{{StructName}}Service) Find(params map[string]interface{}) ([]et.{{StructName}}, error) {
	{{StructLowerEntityName}}Model := model.{{StructName}}Model{}
	{{StructLowerEntityName}}List, err := {{StructLowerEntityName}}Model.Find(params)
	if err != nil {
		return nil, err
	}
	return {{StructLowerEntityName}}List, nil
}

func (c *{{StructName}}Service) FindById(id int) (*et.{{StructName}}, error) {
	{{StructLowerEntityName}}Model := model.{{StructName}}Model{}
	return {{StructLowerEntityName}}Model.GetById(id)
}

func (c *{{StructName}}Service) Insert({{StructLowerEntityName}} *et.{{StructName}}) (err error) {
	{{StructLowerEntityName}}Model := model.{{StructName}}Model{}
	err = {{StructLowerEntityName}}Model.Insert({{StructLowerEntityName}})
	if err != nil {
		return err
	}
	return nil
}

func (c *{{StructName}}Service) UpdateById(id int, {{StructLowerEntityName}} *et.{{StructName}}) (has int64, err error) {
	{{StructLowerEntityName}}Model := model.{{StructName}}Model{}
	has, err = {{StructLowerEntityName}}Model.UpdateById(id, {{StructLowerEntityName}})
	return
}`
